import { IRawQuestion } from '@/types'

/**
 * 对象转url参数
 * @param obj 对象
 * @returns url参数
 */
export function obj2query(obj: Record<string, string | number>) {
  return Object.keys(obj).filter(key => obj[key] !== undefined).map(key => `${key}=${obj[key]}`).join('&')
}

export function formatQuestion(raw: IRawQuestion) {
  const { examTitle: title, correct, answer } = raw
  const options = ['ema', 'emb', 'emc', 'emd'].map(key => {
    return {
      label: raw[key],
      value: key.replace('em', '').toUpperCase()
    }
  })
  return {
    title,
    answer,
    correct,
    options
  }
}
